//动态
function gymup(){
	$("#uploadfile").click();
}
function gymupload(url){
	$("[name='path']").val(url);
	$("#imgview").html('<img src="'+url+'" width="100" height="80">');
}
function dynamicx(obj,id){
	var t=$(obj).val();
	$.post("index.php?ac=t_dynamic&ts=setxid",
			{
				id:id,
				xid:t
			},
			function(msg){
			});
}
//考试
function deltoption(obj){
	var cr=new Array('A','B','C','D','E','F','G','H','I','J','K');
	$(obj).parent("div").remove();
	$(".optionlist").each(function(){
		var k=$(this).index();
		$(this).find(".opsinfo").text('选项'+cr[k]);
	})
}
function addtoption(obj){
	var cr=new Array('A','B','C','D','E','F','G','H','I','J','K');
	var h="<div class='kcb optionlist'><div class='flft mar opsinfo'></div><input type='text' class='flft form-control mar' name='options[]' style='width:500px;' value=''><button type='button' class='btn btn-success flft' onclick=deltoption(this)>删除</button></div>";
	$(obj).parent("div").before(h);
	$(".optionlist").each(function(){
		var k=$(this).index();
		$(this).find(".opsinfo").text('选项'+cr[k]);
	})
}
function uploadtest(id){
	var h=$("#upfileform").attr("action");
	if($("#modal_form").length>0){
		var s=$("#modal_form").attr("action");
		if(geturlpara(s,"id")!=0){
			id=geturlpara(s,"id");
		}
	}else{
		h=changeurlpar(h,"ty","1");
	}
	h=changeurlpar(h,"id",id);
	$("#upfileform").attr("action",h);
	$("#uploadfile").click();
}
function upttest(url,id,n,count){
	if(id<0){
		var h=$("#modal_form").attr("action");
		h=changeurlpar(h,"id",id);
		$("#modal_form").attr("action",h);
	}
	var w=$("[name='path']").val();
	if(w!=''){
		url=w+','+url;
	}
	$("[name='path']").val(url);
	if(parseInt($("#testnum").val())>0){
		n+=parseInt($("#testnum").val());
		count+=parseInt($("#count").val());
	}
	$("#testnum").val(n);
	$("#count").val(count);
	if(n>0){
		var t='上传成功！本次共上传'+n+'题，共计：'+count+'分';
	}else{
		var t='上传失败，本次上传没有题目录入！';
	}
	$("[name='path']").prev("span").text(t);
	$("[name='count']").val(count);
}
//培训
function tviewtt(obj,id,ty){
	var t=$(obj).parent("div").index();
	var w=getmouse(event);
	var u=w.split(',');
	var x=parseInt(u[0]);
	var y=parseInt(u[1]);
	$.post("index.php?ac=t_training&ts=tviewtt",
			{
				id:id,
				ty:t,
				isty:ty
			},
			function(msg){
				$(".mt_ad").show().html(msg);
				$(".mt_ad").css("left",x);
				$(".mt_ad").css("top",y);
				$(".mt_ad").css("width","70px");
			});
}
function tdeltt(t,id,ty){
	var a=$("[name='ksid']").val().split(',');
	a.splice(t,1);
	$("[name='ksid']").val(a.join(','));
	$(".glinfo:eq("+t+")").remove();
	$(".glbu").removeAttr("disabled");
	$(".glbu").attr("onclick","gltest("+id+","+ty+")")
}
function gltest(id,ty){
	var a=$("[name='ksid']").val()
	var w=getmouse(event);
	var u=w.split(',');
	var x=parseInt(u[0]);
	var y=parseInt(u[1]);
	$.post("index.php?ac=t_training&ts=gltest",
			{
				id:id,
				ksid:a,
				ty:ty
			},
			function(msg){
				$(".mt_ad").show().html(msg);
				$(".mt_ad").css("left",x);
				$(".mt_ad").css("top",y);
				$(".mt_ad").css("width","500px");
				$(".mt_ad").css("min-height","50px");
			});
}
function seltcheck(obj,ty){
	var id=$(obj).attr("vid");
	var nm=$(obj).attr("vname");
	var a=$("[name='ksid']").val();
	var h="<div class='kcb glinfo'><span class='hblue hc' onclick=tviewtt(this,"+id+","+ty+")>"+nm+"</span></div>";
	if(a!='' && a!='0'){
		id=a+','+id;
		h=$(".gllist").html()+h;
	}
	$("[name='ksid']").val(id);
	$(".gllist").html(h)
	$(".glbu").removeAttr("onclick");
	$(".glbu").attr("disabled","disabled");
}
function uploadtrface(){
	$("#upfileform").attr("action","index.php?ac=t_training&ts=uppic");
	$("#uploadfile").attr("accept","image/*");
	$("#uploadfile").click();
}
function uptrface(url){
	$("[name='face']").val(url);
	$("#trimg").html('<img src="'+url+'" width="100" height="100">');
}
function uploadtr(){
	$("#upfileform").attr("action","index.php?ac=t_training&ts=upload");
	$("#uploadfile").attr("accept","application/pdf,video/mp4");
	$(".loadingimg").html('<img class="flft mar" src="/public/Images/loading6.gif" width="30" heiht="30"><span class="flft">正在上传中……</span>');
	$("#uploadfile").click();
}
function uptr(fnm,url,ty){
	$(".loadingimg").html('');
	var yu=$("[name='uptrurl']").val();
	var fl='<div class="kcb"><div class=" flft hblue upname h mar" onclick="deluptr(this)" title="点击删除">'+fnm+'</div><button type="button" class="btn btn-success flft" onclick="viewtr(this)">预览</button></div>';
	if(yu!=''){
		url=yu+','+url;
		ty=$("[name='istype']").val()+','+ty;
		fl=$(".flist").html()+fl;
		fnm=$("[name='uptrnm']").val()+','+fnm;
	}
	$(".flist").html(fl);
	$("[name='uptrurl']").val(url);
	$("[name='uptrnm']").val(fnm);
	$("[name='istype']").val(ty);
	$(".viewbutton").show();
//	alert('上传成功！');
}
function deluptr(obj){
	var t=$(obj).parent(".kcb").index();
	var url=$("[name='uptrurl']").val();
	var fnm=$("[name='uptrnm']").val();
	var ty=$("[name='istype']").val();
	var ua=url.split(',');
	var fa=fnm.split(',');
	var ta=ty.split(',');
	ua.splice(t,1);
	fa.splice(t,1);
	ta.splice(t,1);
	var up='';
	var fp='';
	var tp='';
	if(ua.length>0){
		up=ua.join(',');
		fp=fa.join(',');
		tp=ta.join(',')
	}
	$("[name='uptrurl']").val(up);
	$("[name='uptrnm']").val(fp);
	$("[name='istype']").val(tp);
	$(obj).parent(".kcb").remove();
	if(up==''){
		$(".viewbutton").hide();
	}
}
function viewtr(obj){
	var t=$(obj).parent(".kcb").index();
	var url=$("[name='uptrurl']").val();
	var ua=url.split(',');
	window.open(ua[t]);
}
function viewtuser(id){
	var w=getmouse(event);
	var u=w.split(',');
	var x=parseInt(u[0]);
	var y=parseInt(u[1]);
	$.post("index.php?ac=t_training&ts=viewtuser",
			{
				id:id
			},
			function(msg){
				$(".mt_ad").show().html(msg);
				$(".mt_ad").css("left",x);
				$(".mt_ad").css("top",y);
				$(".mt_ad").css("width","700px");
				$(".mt_ad").css("max-height","400px");
				$(".mt_ad").css("overflow-y","auto");
				$(".mt_ad").css("padding-left","20px");
			});
}
function viewtbxuser(id){
	var w=getmouse(event);
	var u=w.split(',');
	var x=parseInt(u[0]);
	var y=parseInt(u[1]);
	$.post("index.php?ac=t_training&ts=viewtbxuser",
			{
				id:id
			},
			function(msg){
				$(".mt_ad").show().html(msg);
				$(".mt_ad").css("left",x-300);
				$(".mt_ad").css("top",y);
				$(".mt_ad").css("width","600px");
				$(".mt_ad").css("max-height","400px");
				$(".mt_ad").css("overflow-y","auto");
				$(".mt_ad").css("padding-left","20px");
			});
}
function gettusers(id){
	var w=getmouse(event);
	var u=w.split(',');
	var x=parseInt(u[0]);
	var y=parseInt(u[1]);
	$.post("index.php?ac=t_training&ts=gettusers",
			{
				id:id
			},
			function(msg){
				$(".mt_ad").show().html(msg);
				$(".mt_ad").css("left",x);
				$(".mt_ad").css("top",y);
				$(".mt_ad").css("width","700px");
				$(".mt_ad").css("max-height","200px");
				$(".mt_ad").css("overflow-y","auto");
				$(".mt_ad").css("padding-left","20px");
			});
}
function trclass(obj){
	var id=$(obj).val();
	$.post("index.php?ac=ajax&ts=gettclass",
			{
				id:id
			},
			function(msg){
				$(".tclass").html(msg);
			});
}
function ckcontract_tab1(ty,pg){
	var id=$("#id").val();
	$.post("index.php?ac=addajax&ts=chkcontabbb1",
			{
				id:id,
				ty:ty,
				pg:pg
			},
				function(msg){
					$(".contract_con").html(msg);
			});
}
function trsub(){
	if($("[name='uptrurl']").val()==''){
		$(".modalsub").removeAttr("disabled").attr("onclick","dissub(this)");
		alert('请上传资料');
		return false;
	}
	if($("[name='tcid']").val()==0||$("[name='xcid']").val()==0){
		$(".modalsub").removeAttr("disabled").attr("onclick","dissub(this)");
		alert('请选择分类');
		return false;
	}else{
		if($("[name='isv']:checked").val()==1){
			if($("[name='dids']").val()==''&&$("[name='gwids']").val()==''&&$("[name='zwids']").val()==''&&$("[name='uids']").val()==''&&$("[name='gids']").val()==''&&$("[name='rzdate']").val()==''){
				$(".modalsub").removeAttr("disabled").attr("onclick","dissub(this)");
				alert('请选择可见范围');
				return false;
			}
		}
	}
	return true;
}
//群组管理
function gpop(obj,ty,isty){
	$.post("index.php?ac=ajax&ts=getgpstr",
			{
				ty:ty,
				isty:isty
			},
			function(msg){
				$(obj).attr("data-content",msg).popover('show');
			});
}
function gpopt(obj,isty){
	var id=$(obj).attr("vid");
	var nm=$(obj).attr("vname");
	var ty=$(obj).attr("tid");
	if(ty==1){
		var str='dids';
	}else if(ty==2){
		var str='gwids';
	}else if(ty==3){
		var str='zwids';
	}else if(ty==4){
		var str='gids';
	}
	setpara(id,nm,str,str,ty,isty);
}
function chkusers(isty){
	var s=$("#uid").val();
	var arr=s.split('|');
	setpara(arr[0],arr[1],"uids","uids",0,isty);
}
function chkuser(ids,str,isty){
	var s=$("#"+ids).val();
	var arr=s.split('|');
	setpara(arr[0],arr[1],str,str,0,isty);
}
function seluser(obj,str,um){
	var s=$(obj).val();
	if(trim(s)==''){
		return;
	}
	$.post("index.php?ac=ajax&ts=gymgetusers",
			{
				str:s,
				um:um
			},
			function(msg){
				$("#"+str).html(msg);
			});
}
function selusers(obj){
	var s=$(obj).val();
	if(trim(s)==''){
		return;
	}
	$.post("index.php?ac=ajax&ts=getusers",
			{
				str:s
			},
			function(msg){
				$("#userlist").html(msg);
			});
}
function mailtogp(id){
	$.post("index.php?ac=h_group&ts=mailtogp",
			{
				id:id
			},
			function(msg){
				location.href='mailto: '+msg;
			});
}
//员工管理
function userplop(obj,ty){
	$.post("index.php?ac=ajax&ts=getupstr",
			{
				ty:ty
			},
			function(msg){
				$(obj).attr("data-content",msg).popover('show');
			});
}
function userplopt(obj){
	var id=$(obj).attr("vid");
	var nm=$(obj).attr("vname");
	var ty=$(obj).attr("tid");
	if(ty==1){
		$("[name='did']").val(id);
		$(".dname").text(nm);
	}else if(ty==2){
		$("[name='gwid']").val(id);
		$(".gname").text(nm);
	}else{
		$("[name='zwid']").val(id);
		$(".zname").text(nm);
	}
}
function userplopd(obj,ty){
	if(ty==1){
		$("[name='did']").val(0);
	}else if(ty==2){
		$("[name='gwid']").val(0);
	}else{
		$("[name='zwid']").val(0);
	}
	$(obj).text('');
}
function ckcontract_tab(ty,pg){
	var id=$("#userid").val();
	$.post("index.php?ac=addajax&ts=chkcontabbb",
			{
				id:id,
				ty:ty,
				pg:pg
			},
				function(msg){
					$(".contract_con").html(msg);
			});
}
function userop(obj,uid,gid){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=h_group&ts=getuserop",
			{
				uid:uid,
				gid:gid
			},
			function(msg){
				if(msg!=''){
					$(".mt_ad").show().html(msg);
					$(".mt_ad").css("left",x+20);
					$(".mt_ad").css("top",y+15);
					$(".mt_ad").css("width","50px");
				}
			});
}
function delgpuser(uid,gid){
	$.post("index.php?ac=h_group&ts=delgpuser",
			{
				uid:uid,
				gid:gid
			},
				function(msg){
					location.reload();
			});
}
//组织架构
function mshow(obj,id,l){
	if($(obj).text()=='+'||$(obj).prev("span").text()=='+'){
		$(".lv"+id+".lev"+l).show().removeClass("dison").addClass("ison");
		$(".ison.lv"+id).show();
		if($(obj).text()=='+'){
			$(obj).text('-');
		}else{
			$(obj).prev("span").text('-');
		}
	}else{
		$(".lv"+id).hide();
		$(".lv"+id+".lev"+l).removeClass("ison").addClass("dison");
		if($(obj).text()=='-'){
			$(obj).text('+');
		}else{
			$(obj).prev("span").text('+');
		}
	}
}
function mshowc(obj,id,cid,w){
	var g="lv"+id;
	var l=parseInt(w/50)-1;
	$(obj).removeAttr("onclick").attr("onclick","mshow(this,"+id+","+l+")");
	if($(obj).text()=='+'){
		$(obj).text('-');
	}else{
		$(obj).prev("span").text('-');
	}
	$.post("index.php?ac=ajax&ts=mshowc",
			{
				id:id,
				cid:cid,
				wd:w
			},
				function(msg){
					$("#"+g).after(msg);
			});
}


////////////////////////////////////////////////////////////////////////////////////基本设置
function gymtitle(u,s){
	var gymtt=getCookie(s);
	var tt=new Array();
	var t=$(u).val();
	$("[name='gymtt[]']").each(function(){
		if($(this).is(":checked")==true){
			tt.push($(this).val());
		}
	})
	var v=tt.join(',');
	var date=new Date();
	date.setTime(date.getTime()+365*24*3600*1000);
	document.cookie=s+"="+v+";expires="+date.toGMTString();
	if($(u).is(":checked")==true){
		$(".gymtitle"+t).show();
	}else{
		$(".gymtitle"+t).hide();
	}
	resizergmain();
}

function modal(id,fun,tt){
	$("#myModalLabel").text(tt);
	$.post("index.php?ac=addajax&ts="+fun,
			{
				id:id
			},
				function(msg){
					$(".modal-body").html(msg);
					$("#myModal").modal("show");
			});
}

function resizergmain(){
	var gs=$("#ssacname").val();
	var gc=getCookie(gs);
	if(parseInt(gc)==1){
		$("#Frame_ttr").text('条件搜索 △')
		$(".topmenu").show();
		$("#ssacname").attr("vid","1");
	}
	var h=$(".page-content").innerHeight()-$(".breadcrumb").outerHeight(true)-$(".topbun").outerHeight(true)-5;
	if($(".topmenu").css("display")!='none'){
		h-=$(".topmenu").outerHeight(true);
	}
	if($(".fdpop").length>0){
		h-=40;
	}
	$(".rgmain").css("height",h);
//	$(".rgmain").css("width",$(".page-content").innerWidth());
	if($(".rgmain table tbody").length>0){
		if($(".rgmain table tbody tr:eq(0)").length>0){
			$(".rgmain table thead tr td").each(function(){
				var ix=$(this).index();
				var iw=$(".rgmain table tbody tr:eq(0) td:eq("+ix+")").css("width");
				$(this).css("width",iw);
			})
			$(".rgmain table tbody tr:eq(0) td").css("padding-top",$(".rgmain table thead").outerHeight(true));
		}else{
			$(".rgmain table thead").css("position","relative");
		}
	}
}

//通用表格列数显示控制
$(document).ready(function(){
	var screenh=document.documentElement.clientHeight;
	$("#main,.page-sidebar,.page-content").css("height",screenh-42);
	resizergmain();
	if($("#fdcgkcenter").length>0){
		$.post("index.php?ac=ajax&ts=cgkcenter",
				{
					ty:1
				},
					function(msg){
						$("#fdcgkcenter").attr("data-content",msg);
				});
	}

//	$("[data-toggle='popover']").click(function(){
//		$(this).popover("show");
//	})
	$(document).on('click',"[data-toggle='popover']",function(){
		$(this).popover("show");
	})

	$(".sidebar").click(function(){
		if($(".page-sidebar").css("display")=='block'){
			$(".page-sidebar").hide();
			$(".page-content").css("width","100%");
		}else{
			var screenw=$("#main").innerWidth();
			$(".page-sidebar").show();
			var elew=$(".page-sidebar").outerWidth(true);
			if($(".page-sidebar").css("position")!='absolute'){
				$(".page-content").css("width",screenw-elew-1);
			}
		}
		resizergmain()
	})
	$(".rgmain").scroll(function(){
//		$(".rgmain .table1 thead tr").css("top",$(".rgmain").scrollTop());
	})
	$("[name='keywords']").keydown(function(e){
		if(e.which==13){
			$(this).next("span").click();
		}
	})
	$("#pageindex").keydown(function(e){
		if(e.which==13){
			$(this).next().next("div").click();
		}
	})
	$("#fdsearch").keydown(function(e){
		if(e.which==13){
			$(this).next("div").click();
		}
	})
	$("#Frame_ttr").click(function(){
		var gs=$("#ssacname").val();
		var gt=$("#ssacname").attr("vid");
		var date=new Date();
		date.setTime(date.getTime()+365*24*3600*1000);
		if(parseInt(gt)==0){
			document.cookie=gs+"=1;expires="+date.toGMTString();
			$("#ssacname").attr("vid","1");
			$(this).text("条件搜索 △");
			$(".topmenu").show();
			resizergmain();
		}else{
			document.cookie=gs+"=0;expires="+date.toGMTString();
			$("#ssacname").attr("vid","0");
			$("#Frame_ttr").text("条件搜索 ▽");
			$(".topmenu").hide();
			resizergmain();
		}
	})
	$(".contract_tab").click(function(){
		if($(this).hasClass(".ftabh")==false){
			$(".ftabb").addClass("ftab").removeClass("ftabh ftabb");
			$(this).addClass("ftabh ftabb").removeClass("ftab");
			ckcontract_tab($(this).index(),1);
		}
	})
	$(".contract_tab1").click(function(){
		if($(this).hasClass(".ftabh")==false){
			$(".ftabb").addClass("ftab").removeClass("ftabh ftabb");
			$(this).addClass("ftabh ftabb").removeClass("ftab");
			ckcontract_tab1($(this).index(),1);
		}
	})
	$(".cclose").click(function(){
		$("#cwin").hide();
	})
	//手机字符替换
	$(".rgmain table tbody tr").click(function(){
		$(".mobile").each(function(){
			$(this).children("font").text($(this).children(".mbv").text());
		})
		$(this).children(".mobile").children("font").text($(this).children(".mobile").children(".mbs").text());
	})
	$(document).bind('click',function(e){
    	var e = e || window.event; //浏览器兼容性
    	var elem = e.target || e.srcElement;
    	while (elem) { //循环判断至跟节点，防止点击的是div子元素
    	if (elem.className && (elem.className.indexOf("popover")>0 || elem.className.indexOf("popovertt")>0)) {
    	return;
    	}
    	elem = elem.parentNode;
    	}
    	$(".popover").popover("hide");
	});
	$(document).bind('click',function(e){
    	var e = e || window.event; //浏览器兼容性
    	var elem = e.target || e.srcElement;
    	while (elem) { //循环判断至跟节点，防止点击的是div子元素
    	if (elem.className && (elem.className.indexOf("mt_ad")>0 || elem.className.indexOf("mtadtt")>0)) {
    	return;
    	}
    	elem = elem.parentNode;
    	}
    	$(".mt_ad").hide();
	});
	$(document).on('keyup',"[type='tel']",function(){
		if(ismobile($(this).val())){
			$(this).removeAttr("style");
		}
	})
	$(document).on('change',".selectreadonly",function(){
		var t=$(this).next("input").val();
		$(this).val(t);
	})
	$("#uploadfile").bind("change",function(){
		if($(this).val()==''){
			return;
		}
		$("#upfileform").submit();
		$(this).val('');
	});
	//登录///////////////////////////////////////////////////////////
	//记住我
	$("[name='rememberme']").click(function(){
		if($(this).is(":checked")==true){
			$(this).next("font").css("color","#999");
			var s=$("#mobile").val();
			if(s!=''){
				var date=new Date();
				date.setTime(date.getTime()+365*24*3600*1000);
				document.cookie="gym_admin="+s+";expires="+date.toGMTString();
			}
		}else{
			$(this).next("font").css("color","#ccc");
			var date = new Date();
			date.setTime(date.getTime() - 10000);
			document.cookie="gym_admin='';expires="+date.toGMTString();
		}
	});
	$("#mobile").keyup(function(){
		var s=$(this).val();
		if(ismobile(s)){
			$.post("index.php?ac=login&ts=checkmb",
					{
						mb:s
					},
						function(msg){
							if(msg=='1'){
								$("#getcode").attr("onclick","mtbtime(this,60);getmbcode(this)");
								$("#getcode").addClass("yaz").removeClass("yzm");
							}else{
								$("#getcode").attr("onclick","alert('请输入正确的管理员手机号！')");
								$("#getcode").addClass("yzm").removeClass("yaz");
							}
					});
		}else{
			$("#getcode").attr("onclick","alert('请输入正确的管理员手机号！')");
			$("#getcode").addClass("yzm").removeClass("yaz");
		}
	});
});

//登录
function getmbcode(obj){
	var mb=$("[name='mobile']").val();
	var t=60;
//	var m=getrnum(100000,999999);
//	$("[name='code']").val(m);
	$.post("index.php?ac=login&ts=sendcode",
			{
				mb:mb
			},
				function(msg){
			});
}
function mtbtime(obj,t){
	if(t==0){
		$(obj).attr("onclick","mtbtime(this,60);getmbcode(this)");
		$(obj).addClass("yaz").removeClass("yzm");
		$(obj).text("获取验证码");
	}else{
		$(obj).removeAttr("onclick");
		$(obj).addClass("yzm").removeClass("yaz");
		$(obj).text("倒计时"+t+"秒");
		t--;
		setTimeout(function(){
			mtbtime(obj,t);
		},1000);
	}
}
//////////////////////////////////////////////////////////////////////////////
//通用搜索JS
function checksubkw(){
	var w=$("#keyword").val();
	if(w==''){
		alert('搜索内容不能为空！');
		return false;
	}else{
		return true;
	}
}
//修改URL参数
function changeurlpar(url,w,t){
	var str='';
	if(url.indexOf('?') != -1){
		str=url.split('?');
		var str1=str[1].split('&');
		var s='';
		var a=0;
		for (var i=0;i<str1.length;i++){
			var str2=str1[i].split('=');
			if(str2[0]==w){
				str1[i]=w+'='+t;
				a=1;
				break;
			}
		}
		if(a==0){
			str1[str1.length]=w+'='+t;
		}
		var nurl=str1.join('&');
		return str[0]+'?'+nurl;
	}else{
		return url+'?'+w+'='+t;
	}
}
function delurlpar(url,w){
	var str='';
	if(url.indexOf(w)==-1){
		return url;
	}
	if(url.indexOf('?') != -1){
		str=url.split('?');
		var str1=str[1].split('&');
		var s='';
		var a=0;
		for (var i=0;i<str1.length;i++){
			var str2=str1[i].split('=');
			if(str2[0]==w){
				str1.splice(i,1);
				a=1;
				break;
			}
		}
		var nurl=str1.join('&');
		return str[0]+'?'+nurl;
	}else{
		return url;
	}
}
function geturlpar(w){
	var str='';
	var a='';
	var url=location.href;
	if(url.indexOf('?') != -1){
		str=url.split('?');
		var str1=str[1].split('&');
		var s='';
		for (var i=0;i<str1.length;i++){
			var str2=str1[i].split('=');
			if(str2[0]==w){
				a=str2[1];
			}
		}
	}
	return a;
}
function geturlpara(url,w){
	var str='';
	var a='';
	if(url.indexOf('?') != -1){
		str=url.split('?');
		var str1=str[1].split('&');
		var s='';
		for (var i=0;i<str1.length;i++){
			var str2=str1[i].split('=');
			if(str2[0]==w){
				a=str2[1];
			}
		}
	}
	return a;
}

function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function getCookie(name){
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return '';
}
function getmictm(v){
	return Date.parse(new Date(v))/1000;
}
function gym_ssub(){
	var s=$("#gymsearch").attr("action");
	var kw=$("[name='keyword']").val();
	if(kw==''){
		return;
	}
	$.post("index.php?ac=ajax&ts=tounicode",
			{
				str:kw
			},
				function(msg){
				if(s.indexOf('?')>-1){
					s+='&keyword='+msg;
				}else{
					s+='?keyword='+msg;
				}
				location.href=s;
			});
}
function gym_ssubt(){
	var kw=$("[name='keywords']").val();
	var s='index.php?ac=search';
	if(kw==''){
		return;
	}
	$.post("index.php?ac=ajax&ts=tounicode",
			{
				str:kw
			},
				function(msg){
				s+='&keywords='+msg;
				location.href=s;
			});
}
function u2unicode(str){
	$.post("index.php?ac=ajax&ts=tounicode",
			{
				str:str
			},
				function(msg){
				return msg;
			});
}
function gymselpagesize(obj){
	var t=$(obj).val();
	var date=new Date();
	date.setTime(date.getTime()+365*24*3600*1000);
	document.cookie="gym_pagesize="+t+";expires="+date.toGMTString();
	location.reload();
}
function ismobile(t){
	var partten = /^1\d{10}$/g;
	if(partten.test(t)){
		return true;
	}else{
		return false;
	}

}

function getscreenheight(){
	return screen.availHeight;
}
function checkall(){
	if($("#ckall").is(":checked")==true){
		$("[name='ckid[]']").attr("checked",true);
	}else{
		$("[name='ckid[]']").attr("checked",false);
	}
}
function dissub(obj){
	var a=0;
	if($("#textareahf").length>0){
		$("#modal_form textarea").each(function(){
			$(this).val($(this).val().replace(/\n/g,'<br>').replace(/\r/g,''));
		})
	}
	$(":required").each(function(){
		if(trim($(this).val())==''){
			alert('请填写所有必填项！');
			a=1;
			return false;
		}
	})
	$("[type='tel']").each(function(){
		if(!ismobile($(this).val())){
			$(this).css("border","#ff0000 1px solid");
			alert('请填写正确的手机号码！');
			a=1;
			return false;
		}
	})
	if(a==0){
		$(obj).attr("disabled","disabled");
		$(obj).removeAttr("onclick");
		$("#modal_form").submit();
	}
}
//获取随机数
function getrnum(Min,Max)
{
var Range = Max - Min;
var Rand = Math.random();
return(Min + Math.round(Rand * Range));
}
//获取鼠标坐标
function getmouse(e){
	var oe=e||window.event;
	var x=oe.clientX+document.body.scrollLeft + document.documentElement.scrollLeft
	var y=oe.clientY+document.body.scrollTop + document.documentElement.scrollTop;
	return x+','+y;
}
//设置多参数
function setpara(id,nm,str1,str2,ty,isty){
	var a=$("[name='"+str1+"']").val();
	var b=$("."+str2).html();
	if(isty==0){
		var h='<div class="flft hblue h mar" onclick=delpara(this,"'+str1+'","'+str2+'","'+isty+'") title="点击取消">'+nm+'</div>';
	}else if(isty==1){
		var h='<div class="flft mar"><input type="checkbox" name="ids[]" value="'+id+'|'+ty+'">&nbsp;<span class="hblue h" onclick=delpara(this,"'+str1+'","'+str2+'","'+isty+'") title="点击取消">'+nm+'</span></div>';
	}
	if(a==''){
		$("[name='"+str1+"']").val(id);
		$("."+str2).html(h);
	}else{
		var arr=a.split(',');
		var d=b.split(', ');
		var c=0;
		for(var i=0;i<arr.length;i++){
			if(arr[i]==id){
				c=1;
				break;
			}
		}
		if(c==0){
			arr.push(id);
			d.push(h);
		}
		$("[name='"+str1+"']").val(arr.join(','));
		$("."+str2).html(d.join(''));
	}
}
function delpara(obj,str1,str2,isty){
	if(isty==0){
		var l=$(obj).index();
		$(obj).remove();
	}else if(isty==1){
		var l=$(obj).parent("div").index();
		$(obj).parent("div").remove();
	}
	var a=$("[name='"+str1+"']").val();
//	var b=$("."+str2).html();
	var arr=a.split(',');
//	var d=b.split(', ');
	arr.splice(l,1);
//	d.splice(l,1);
	$("[name='"+str1+"']").val(arr.join(','));
//	$("."+str2).html(d.join(', '));
}








//支店管理
function selcenarea(obj,cid,ty){
	var t=$(obj).val();
	$.post("index.php?ac=ajax&ts=selcenarea",
			{
				cid:cid,
				vu:t,
				ty:ty

			},
				function(msg){
					if(ty==1){
						$(".citylist").html(msg);
						$(".arealist").html('');
					}else if(ty==2){
						$(".arealist").html(msg);
					}
			});
}
//切换支店
function fdcgkcenter(obj){
	$(".tmain").val($(obj).attr("vname"));
	$.post("index.php?ac=ajax&ts=centersel",
			{
				cid:$(obj).attr("vid")
			},
				function(msg){
					location.reload();
			});
}
function selcenter(obj,ty){
	$(obj).attr("data-toggle","popover");
	$(obj).attr("data-html",true);
	$(obj).attr("title",'选择支店');
	$(obj).attr("data-placement","auto bottom");
	$.post("index.php?ac=ajax&ts=cgkcenter",
			{
				ty:ty
			},
				function(msg){
					$(obj).attr("data-content",msg).popover("show");
			});
}
function getfdcenter(obj){
	$(".cname").text($(obj).attr("vname"));
	$("[name='isc']").val($(obj).attr("vid"));
	$("#selcen").popover("hide");
}
function ufdcenter(obj){
	var s=$(obj).attr("vid");
	var u=location.href;
	location.href=changeurlpar(u,'isc',s);
}
//区域设置
function chkteacher(obj){
	var t=$(obj).attr("vid");
	var m=$(obj).attr("vname");
	var a=$("[name='tuid']").val();
	var b=$("[name='tuser']").val();
	var h=$(".thlist").html();
	if(a==''){
		a=t;
	}else{
		a+=','+t;
	}
	if(b==''){
		b=m;
	}else{
		b+=','+m;
	}
	var g="<div class='flft hd mar' title='删除' onclick='delteacher(this)'>"+m+"</div>";
	$(".thlist").html(h+g);
	$("[name='tuid']").val(a);
	$("[name='tuser']").val(b);
}
function delteacher(obj){
	var j=$(obj).index();
	var a=$("[name='tuid']").val();
	var b=$("[name='tuser']").val();
	var d=a.split(',');
	var m=b.split(',');
	d.splice(j,1);
	m.splice(j,1);
	a=d.join(',');
	b=m.join(',');
	$("[name='tuid']").val(a);
	$("[name='tuser']").val(b);
	$(obj).remove();
}
function thapply(obj,id){
	$.post("index.php?ac=thapply&ts=op",
			{
				id:id
			},
			function(msg){
				$("#thop"+id).text('已处理');
				$(obj).remove();
			});
}
//课程设置
function uppic(){
	if($("#textareahf").length>0){
		$("#upfileform").attr("action",'index.php?ac=class_set&ts=upload');
	}
	$("#uploadfile").click();
}
function uppicurl(url){
	$("#fduppic").val(url);
	$("#fduplist").html('<img class="he" src="'+url+'" title="删除图片" onclick="deluppicurl()" width="200" height="160">');
	$("#fdpiclist").removeClass("dishidden");
	$("[onclick='uppic()']").attr("disabled","disabled");
}
function deluppicurl(){
	$("#fduppic").val('');
	$("#fduplist").html('');
	$("#fdpiclist").addClass("dishidden");
	$("[onclick='uppic()']").removeAttr("disabled");
}
function uploadpic(k){
	var url='index.php?ac=class_set&ts=upload&id='+k;
	$("#upfileform").attr("action",url);
	$("#uploadfile").click();
}
function fduppic(url,unm,k){
	var m='fduppic'+k;
	var s=$("#"+m).val();
	if(s==''){
		$("#"+m).val(url);
		$("#fdupnm"+k).val(unm);
		var h='<div class="flft mar hd" onclick="delfdpic(this,'+k+')" title="删除图片">'+unm+'</div>';
		$("#fduplist"+k).html(h);
	}else{
		s+=','+url;
		var v=$("#fdupnm"+k).val()+','+unm;
		var u=s.split(',');
		if(u.length>3){
			alert('最多只能上传三张图片');
			return;
		}else if(u.length==3){
			$("[onclick='uploadpic("+k+")']").attr("disabled","disabled");
		}
		var w=v.split(',');
		var h='';
		for(var i=0;i<u.length;i++){
			h+='<div class="flft mar hd" onclick="delfdpic(this,'+k+')">'+w[i]+'</div>';
		}
		$("#fduplist"+k).html(h);
		$("#"+m).val(u.join(','));
		$("#fdupnm"+k).val(w.join(','));
	}
	$("#fdpiclist"+k).removeClass("dishidden");
}
function delfdpic(obj,k){
	var ix=$(obj).index();
	var u=$("#fduppic"+k).val();
	var v=$("#fdupnm"+k).val();
	var a=u.split(',');
	var b=v.split(',');
	a.splice(ix,1);
	b.splice(ix,1);
	$("#fduppic"+k).val(a.join(','));
	$("#fdupnm"+k).val(b.join(','));
	$(obj).remove();
	$("[onclick='uploadpic("+k+")']").removeAttr("disabled");
}
//教材管理
function zpjiaocai(){
	var t=$("[name='price']").val();
	var n=$("[name='allnum']").val();
	if(t==''){
		t=0;
	}
	if(n==''){
		n=0;
	}
	var h=t*n;
	$("[name='zprice']").val(h);
}
function chkjiaocai(obj){
	var t=$(obj).val();
	if(t==''){
		return;
	}
	var h=$("#kcnum").val();
	if(parseInt(t)>parseInt(h)){
		alert('领取数量不能大于现有数量！');
		$(obj).val(h);
	}
}
//课程表
function chkxx(obj,id,ty){
	if(!$(obj).hasClass("kcpj1")){
		$(obj).removeClass("kcpj").addClass("kcpj1");
	}
	$(obj).prevAll().removeClass("kcpj").removeClass("kcpj1").addClass("kcpj1");
	$(obj).nextAll().removeClass("kcpj").removeClass("kcpj1").addClass("kcpj");
	var s=parseInt($(obj).index())+1;
	$.post("index.php?ac=wclass&ts=chkxx",
			{
				id:id,
				score:s,
				ty:ty
			},
			function(msg){

			});
}
function kcbop(obj,id,tm){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=wclass&ts=kcbop",
			{
				id:id,
				tm:tm
			},
			function(msg){
				var mg=msg.split('|');
				if(parseInt(mg[0])==3){
					var h=70;
				}else if(parseInt(mg[0])==4){
					var h=95;
				}else if(parseInt(mg[0])==5){
					var h=120;
				}else if(parseInt(mg[0])==2){
					var h=50;
				}else{
					var h=140;
				}
				$(".mt_ad").show().html(mg[1]);
				$(".mt_ad").css("left",x+30);
				$(".mt_ad").css("top",y-h);
				$(".mt_ad").css("width","50px");
//				$(".mt_ad").css("height","100px");
			});
}
function kcbopf(id,ty){
	$.post("index.php?ac=wclass&ts=kcbopf",
			{
				id:id,
				ty:ty
			},
			function(msg){
				if(msg=='1'){
					alert('操作成功');
					location.reload();
				}else if(msg=='0'){
					alert('顺延最后一周课程时间有冲突，请确认后再操作！');
				}else if(msg=='2'){
					alert('前面尚有课未签到，请先将前面课程签到！');
				}else if(msg=='3'){
					alert('当前时间不能签到该课程！');
				}
			});
}
function ctgq(obj,id){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=ajax&ts=ctgq",
			{
				id:id
			},
			function(msg){
				if(msg!=''){
					$(".mt_ad").show().html(msg);
					$(".mt_ad").css("left",x-130);
					$(".mt_ad").css("top",y-105);
					$(".mt_ad").css("width","250px");
//					$(".mt_ad").css("height","100px");
				}
			});
}
function cttkop(obj,id){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=ajax&ts=cttkop",
			{
				id:id
			},
			function(msg){
				if(msg!=''){
					$(".mt_ad").show().html(msg);
					$(".mt_ad").css("left",x-130);
					$(".mt_ad").css("top",y-105);
					$(".mt_ad").css("width","250px");
				}
			});
}
function chkfrto(t){
	if(t==-1){
		$(".tolist").hide();
	}else if(t==-2){
		$(".tolist").show();
	}else{
		var frid=$("[name='frid']").val();
		var slid=$("#slid").val();
		var etm=$("#etm").val();
		var syk=$("#syk").val();
		var lvid=$("#lvid").val();
		var isk=$("[name='isk']:checked").val();
		$.post("index.php?ac=ajax&ts=chkfrto",
				{
					id:t,
					frid:frid,
					slid:slid,
					etm:etm,
					syk:syk,
					lvid:lvid
				},
				function(msg){
					$(".jdinfo").html(msg);
				});
	}
}
function cd_editface(t){
	var s='勾选头像';
	$.post("index.php?ac=addajax&ts=editface",
			{
				id:t
			},
				function(msg){
				$(".ctop font").text(s);
				$(".cw").html(msg);
			});
	$("#cwin").show();
}
function  chkface(u){
	var s=$(u).attr("src");
	$(".faceimg").attr("src",s);
	$("#path").val(s);
	$("#cwin").hide();
}
//市场管理
function delmc(obj,k,ka,kb){
	$(obj).parent().parent("tr").remove();
	$.post("index.php?ac=mclass&ts=delmc",
			{
				id:k,
				ka:ka,
				kb:kb
			},
			function(msg){
				alert('删除关联成功！');
			});
}
function mprice(){
	var s=0;
	var d;
	$("[name='pr[]']").each(function(){
		d=$(this).val();
		if(d==''){
			d=0;
		}
		s+=parseInt(d);
	})
	$("[name='price']").val(s);
}
//名单管理
function chksty(obj){
	var s=$(obj).val();
	if(s==1){
		$(".isst0").hide();
	}else{
		$(".isst1").hide();
		$(".isst0").show();
	}
}
function initstday(dt){
	var hf=location.href;
	location.href=changeurlpar(hf,'dt',dt);
}
function stkcqd(rid,tid,tm){
	var w=getmouse(event);
	var u=w.split(',');
	var x=parseInt(u[0]);
	var y=parseInt(u[1]);
	$.post("index.php?ac=stkc&ts=stkcqd",
			{
				rid:rid,
				tid:tid,
				tm:tm
			},
			function(msg){
				$(".mt_ad").show().html(msg);
				$(".mt_ad").css("left",x);
				$(".mt_ad").css("top",y-112);
				$(".mt_ad").css("width","70px");
			});
}
function stkcqdop(id,ty){
	$.post("index.php?ac=stkc&ts=stkcqdop",
			{
				id:id,
				ty:ty
			},
			function(msg){
				if(msg=='2'){
					alert('试听时间已过，不能取消！');
				}else{
					location.reload();
				}
			});
}
function stviewqd(obj,id){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=stkc&ts=stviewqd",
			{
				id:id
			},
			function(msg){
				$(".mt_ad").show().html(msg);
				$(".mt_ad").css("left",x+20);
				$(".mt_ad").css("top",y+20);
				$(".mt_ad").css("width","70px");
			});
}
function schleads(obj,str){
	var s=$(obj).val();
	$.post("index.php?ac=stkc&ts=schleads",
			{
				str:s,
				id:str
			},
			function(msg){
				$("#ldlist").html(msg);
				$("[name='lid']").click();
			});
}
function cgstth(obj,rid,tid,tm){
	var s=$(obj).val();
	$.post("index.php?ac=stkc&ts=cgstth",
			{
				rid:rid,
				tid:tid,
				tm:tm,
				uc:s
			},
			function(msg){
				alert('老师已更改');
			});
}
function chkparea(lid){
	$.post("index.php?ac=leads&ts=chkparea",
			{
				id:lid
			},
			function(msg){
				if(msg=='1'){
					modal(lid,'stap','安排试听');
				}else{
					if(confirm('安排试听前，请先选择宝宝所在小区！')){
						location.href="index.php?ac=leads&ts=edit&id="+lid;
					}
				}
			});
}
function auditcon(obj,id){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=contract&ts=auditcon",
			{
				id:id
			},
			function(msg){
				$(".mt_ad").show().html(msg);
				$(".mt_ad").css("left",x+30);
				$(".mt_ad").css("top",y-50);
				$(".mt_ad").css("width","70px");
			});
}
function conaudit(id,ty){
	$.post("index.php?ac=contract&ts=conaudit",
			{
				id:id,
				ty:ty
			},
			function(msg){
				alert('审核成功！');
				location.reload();
			});
}





function chkmarket(cid,ty){
	var isfr=$("[name='isfr']").val();
	if(ty==2){
		var mcid=$("[name='mcid']").val();
	}else{
		var mcid=0;
		$(".mbody").remove();
	}
	var h='';
	$.post("index.php?ac=ajax&ts=chkmc",
			{
				isfr:isfr,
				mcid:mcid,
				cid:cid
			},
			function(msg){
				if(ty==1){
					if($(".mcbody").length==0){
						h='<div class="row mcbody"><div class="col-xs-3 col-md-2 rgt">来源渠道：</div><div class="col-xs-6 col-md-8 mclist">';
						h+=msg;
						h+='</div><div class="col-xs-3 col-md-2"></div></div>';
						$(".frlist").after(h)
					}else{
						$(".mclist").html(msg);
					}
				}else{
					if($(".mbody").length==0){
						h='<div class="row mbody"><div class="col-xs-3 col-md-2 rgt">渠道/活动：</div><div class="col-xs-6 col-md-8 mlist">';
						h+=msg;
						h+='</div><div class="col-xs-3 col-md-2"></div></div>';
						$(".mcbody").after(h)
					}else{
						$(".mlist").html(msg);
					}
				}
			});
}
function addparent(u){
	var b=$(u).parent("div").attr("tid");
	var t=parseInt(b)+1;
	var arr=new Array('爸爸','妈妈','爷爷','奶奶','外公','外婆','其他');
	var h='<div class="con market'+t+' potel" tid="'+t+'"><input type="hidden" name="ish[]" value="0">';
	h+='<input type="text" class="inputsm mar" name="otel0[]" value="" placeholder="家长姓名" required>';
	h+='<select class="inputtx mar" name="otel1[]">';
	for(var i=0;i<7;i++){
		h+='<option value="'+arr[i]+'">'+arr[i]+'</option>';
	}
	h+='</select>'
	h+='<input type="tel" class="inputmd mar addotel" name="otel2[]" placeholder="联系手机" value="" required>';
	h+='<span class="hc mar otl" onclick="delparent(this)">删除</span><span class="hc mar otl" onclick="setparent(this)">设置默认</span>';
	h+='<span class="hc addmk" onclick="addparent(this)">添加家长</div>';
	$(".addmk").remove();
	$(".market"+b).after(h);
}
function delparent(u){
	var b=$(u).parent("div").attr("tid");
	if($(u).parent("div").children().is(".addmk")==true){
		var t=parseInt(b)-1;
		while($(".market"+t).length==0){
			t--;
		}
		var h=$(".market"+t).html()+'<span class="hc addmk" onclick="addparent(this)">添加家长</div>';
		$(".market"+t).html(h)
	}
	$(u).parent("div").remove();
}
function setparent(u){
	var b=$(u).parent("div").attr("tid");
	$(".hred").remove();
	$("[name='ish[]']").val(0);
	$(u).parent().children("[name='ish[]']").val(1);
	var s='<span class="hc mar otl" onclick="delparent(this)">删除</span><span class="hc mar otl" onclick="setparent(this)">设置默认</span>';
	$(".potel").each(function(){
		if($(this).children().is(".otl")==false){
			$(this).children(".addotel").after(s);
		}
	})
	var h='<span class="hred mar">*</span>';
	$(u).parent().find(".addotel").after(h);
	$(u).parent().children(".otl").each(function(){
		$(this).remove();
	})
}
function getbchar(obj){
	var arr=new Array();
	var s=$("[name='bname']").val();
	arr.push(s);
	if($("[name='btname[]']").length>0){
		$("[name='btname[]']").each(function(){
			arr.push($(this).val());
		})
	}
	var str=arr.join(',');
	var h=$("[name='lzm']").val();
	$.post("index.php?ac=ajax&ts=getbchar",
			{
				str:str
			},
			function(msg){
				$("[name='lzm']").val(msg);
			});
}
function addbaby(){
	var h='<div class="con"><input type="text" class="inputsm mar" name="btname[]" value="" placeholder="宝宝姓名" onblur="getbchar(this)" required>';
	h+='<input type="text" class="inputsm mar" name="btename[]" value="" placeholder="宝宝英文名">';
	h+='<select class="inputtx mar" name="btsex[]"><option value="1">男</option><option value="2">女</option></select>';
	h+='<input type="date" class="inputmd mar" name="btbirth[]" placeholder="宝宝生日" value="" onclick="WdatePicker();" required>';
	h+='<span class="hc" onclick="delbaby(this)">删除</span></div>';
	var s=$("#blist").html();
	$("#blist").html(s+h);
	$(".blist").removeClass("dishidden");
}
function delbaby(obj){
	$(obj).parent(".con").remove();
	var s=trim($("#blist").html());
	if(s==''){
		$(".blist").addClass("dishidden");
	}
}
function cgleadsgz(id){
	var t=$("#isgz").val();
	if(t=='D'){
		if(!confirm('改为无效后，该例子将从你的列表中消失，你确认这么做吗？')){
			var w=$("#yisgz").val();
			$("#isgz").val(w);
			return false;
		}
	}
	$.post("index.php?ac=leads&ts=cgleadsgz",
			{
				isgz:t,
				lid:id
			},
			function(msg){
				alert('更改成功！')
			});
}
function leadssh(obj){
	if($(obj).text()=='收起'){
		$(".row").hide();
		$(obj).text('展开');
	}else{
		$(".row").show();
		$(obj).text('收起');
	}
}
function selmname(id,mn){
	$("[name='mname']").val(mn);
	$("[name='mid']").val(id);
}
function selmcname(id,mn){
	$("[name='mcname']").val(mn);
	$("[name='mcid']").val(id);
}
function seladuser(id,mn){
	$("[name='aduser']").val(mn);
	$("[name='aduid']").val(id);
}

function fdleadsfp(obj,id,ty){
	var uid=$(obj).attr("vid");
	var unm=$(obj).attr("vname");
	if(ty==4){
		$("[name='aduinfo']").val(uid+'|'+unm);
		$(".adusershow").text(unm);
	}else{
	$.post("index.php?ac=ajax&ts=setsales",
			{
				id:id,
				ty:ty,
				uid:uid,
				unm:unm
			},
			function(msg){
				alert('设置成功！');
				location.reload();
			});
	}
}
function tsort_leads(t){
	var u=location.href;
	location.href=changeurlpar(u,"issort",t);
}
function selbaby(obj,id){
	var t=$(obj).val();
	$.post("index.php?ac=leads&ts=selbaby",
			{
				id:id,
				blid:t
			},
			function(msg){
				var s=msg.split(',');
				$("[name='bname']").val(s[0]);
				$("[name='ebname']").val(s[1]);
				if(s[2]>0){
					var k=s[2]-1;
					$("[name='sex']").attr("checked",false);
					$("[name='sex']:eq("+k+")").attr("checked","checked");
					$("[name='sex']:eq("+k+")").click();
				}else{
					$("[name='sex']").attr("checked",false);
				}
				$("[name='birthday']").val(s[3]);
			});
}
function chklvs(obj){
	var t=$(obj).val();
	var h=$("[name='valueday']").val();
	if(h==''){
		h=0;
	}
	var q=$("[name='qj']").val();
	if(q==''){
		q=0;
	}
	var arr=new Array(0,15,15,8);
	if($(obj).is(":checked")==true){
		h=parseInt(h)+arr[t];
		q=parseInt(q)+8;
	}else{
		h-=parseInt(arr[t]);
		q-=8;
	}
	$("[name='valueday']").val(h);
	$("[name='qj']").val(q);
}
function sellvs(obj){
	var t=$(obj).val();
	var arr=new Array(0,15,15,8);
	$("[name='valueday']").val(arr[t]);
	$("[name='qj']").val('8');
}
function leadsdj(obj,lid){
	var d=$(obj).prev("input").val();
	if(d==''||d==0){
		return;
	}
	$.post("index.php?ac=leads&ts=leadsdj",
			{
				id:lid,
				dj:d
			},
			function(msg){
				alert('操作成功！');
				location.reload();
			});
}
function leadstkdj(obj,lid){
	var d=$(obj).prev("input").val();
	if(d==''||d==0){
		return;
	}
	$.post("index.php?ac=leads&ts=leadstkdj",
			{
				id:lid,
				dj:d
			},
			function(msg){
				if(msg=='1'){
					alert('操作成功！');
					location.reload();
				}else{
					alert(msg);
				}
			});
}

//合同管理
function selstth(id,ty){
	var dt=$("[name='date']").val();
	var sdt=$("#sdt").val();
	if(dt=='' || (dt==sdt && ty==1)){
		return;
	}
	$("#sdt").val(dt);
	var t=$("[name='isst']:checked").val();
	if(t==1){
		$.post("index.php?ac=leads&ts=getstrm",
				{
					id:id,
					dt:dt
				},
				function(msg){
					$(".sttmlist").html(msg);
					$(".isst1").show();
				});
	}else{
		var tuid=$("[name='tuid']").val();
		$.post("index.php?ac=ajax&ts=getsttimer",
				{
					id:id,
					tuid:tuid,
					dt:dt
				},
				function(msg){
					var mg=msg.split('|');
					$(".kcaplist").html(mg[0]);
					$(".stthlist").html(mg[1]);
				});
	}
}
function selstth1(id){
	var dt=$("[name='date']").val();
	var sdt=$("#sdt").val();
	if(dt=='' || dt==sdt){
		return;
	}
	$("#sdt").val(dt);
	$.post("index.php?ac=ajax&ts=getsttimer1",
			{
				id:id,
				dt:dt
			},
			function(msg){
				if(msg=='1'){
					alert('该课程不能更改为'+dt);
					$(".kcaplist").html('不能更改为'+dt);
				}else{
					$(".kcaplist").html(msg);
				}
			});
}
function selkcaplv(id,ty){
	var lvid=$("[name='lvid']").val();
	var dt=$("[name='sdate']").val();
	var sdt=$("#sdt").val();
	var iswp=0;
	if($("[name='iswp']").is(":checked")==true){
		iswp=1;
//		$("#sls").addClass("dishidden");
//	}else{
//		$("#sls").removeClass("dishidden");
	}
//	if(ty==0 && iswp==0){
//		$.post("index.php?ac=ajax&ts=getlslist",
//				{
//					lvid:lvid
//				},
//				function(msg){
//					$("#slslist").html(msg);
//				});
//	}
	if(dt=='' || (dt==sdt && ty==1)){
		return;
	}
	$("#sdt").val(dt);

	$.post("index.php?ac=ajax&ts=getthtimer",
			{
				id:id,
				lvid:lvid,
				dt:dt,
				iswp:iswp
			},
			function(msg){
				var h=msg.split('|');
				$(".kcaptimer").html(h[0]);
				$(".kcaplist").html(h[1]);
				$(".fdkcap").removeClass("dishidden");
			});
}
function payctmb(obj){
	$("[name='payty']").removeAttr("checked");
	$(obj).prev("input").attr("checked","checked");
	$(obj).prev("input").click();
}
function ctpay(id){
	$.post("index.php?ac=ajax&ts=geturlpic",
			{
				id:id
			},
			function(msg){
				$(".cw").html(msg);
			});
	$("#cwin .cmain").css({"left":"50%","width":"450px","top":"50%","height":"570px","margin-left":"-222px","margin-top":"-300px"});
//	var h=parseInt(document.documentElement.clientHeight*0.6);
	$(".cw").css("height","520px");
	$(".ctop font").text('微信/支付宝扫描二维码付款');
	$("#cwin").show();
}
function ctpaybyp(id){
	var vpz=$("#vpz").val();
	var dt=$("#paydate").val();
	$.post("index.php?ac=ajax&ts=ctpaybyp",
			{
				id:id,
				vpz:vpz,
				dt:dt
			},
			function(msg){
				alert('付款成功！');
				location.reload();
			});
}
function ctpays(){
	$(".cw").html('<img src="/app/home/html/images/finden15_15.png">');
	$("#cwin .cmain").css({"left":"50%","width":"450px","top":"50%","height":"500px","margin-left":"-222px","margin-top":"-250px"});
//	var h=parseInt(document.documentElement.clientHeight*0.6);
	$(".cw").css("height","450px");
	$(".ctop font").text('支付宝扫描二维码付款');
	$("#cwin").show();
}
function fpteacher(obj,id,cid){
	$.post("index.php?ac=ajax&ts=getths",
			{
				cid:cid,
				id:id
			},
			function(msg){
				if(msg=='1'){
					alert('该会员地址没有可分配老师！');
				}else{
					$(obj).attr("data-content",msg).popover('show');
				}
			});
}
function fdthfp(obj,id){
	var uid=$(obj).attr("vid");
	var unm=$(obj).attr("vname");
	$.post("index.php?ac=ajax&ts=setths",
			{
				id:id,
				uid:uid,
				unm:unm
			},
			function(msg){
				alert('操作成功！');
				location.reload();
			});
}

function selfdbaby(obj,id){
	var t=$(obj).val();
	$.post("index.php?ac=ajax&ts=selbaby",
			{
				id:id,
				blid:t
			},
			function(msg){
				var s=msg.split(',');
				$("[name='bname']").val(s[0]);
				$("[name='ebname']").val(s[1]);
				if(s[2]>0){
					var k=s[2]-1;
					$("[name='sex']").removeAttr("checked");
					$("[name='sex']:eq("+k+")").attr("checked","checked");
					$("[name='sex']:eq("+k+")").click();
				}else{
					$("[name='sex']").removeAttr("checked");
				}
				$("[name='birthday']").val(s[3]);
			});
}

//报表管理
function getmarketbb(obj,tm){
	var t;
	if($(obj).text().indexOf('▼')==-1){
		$(".mc"+tm).hide();
		$(".bbmcinfo").hide();
		t=$(obj).text().replace('▲','▼');
	}else{
		$(".bbmclist").hide();
		$(".bbmcinfo").show();
		$(".mkbb").each(function(){
			if($(this).text().indexOf('▼')==-1){
				t=$(this).text().replace('▲','▼');
				$(this).text(t);
			}
		})
		t=$(obj).text().replace('▼','▲');
		if($(".mc"+tm).length>0){
			$(".mc"+tm).show();
		}else{
			$.post("index.php?ac=bb_market&ts=selmc",
					{
						tm:tm
					},
						function(msg){
//							alert(msg)
							$(obj).parent("tr").after(msg);
					});
		}
	}
	$(obj).text(t);
	resizergmain();
}

//系统设置
function chkqxall(u,s){
	if($(u).is(":checked")==true){
		$("."+s).attr("checked",true);
	}else{
		$("."+s).attr("checked",false);
	}
}
function chkmenuqx(u,s,t){
	var a=1;
	$("."+s).each(function(){
		if($(this).attr("vid")==1){
		}else{
			if($(this).is(":checked")==true){
				a=2;
			}
		}
	})
	if(a==1){
		$("."+s+":eq(0)").attr("checked",false);
		$(".ceny"+t).each(function(){
			if($(this).attr("vid")==1){
			}else{
				if($(this).is(":checked")==true){
					a=2;
				}
			}
		})
		if(a==2){
			$(".ceny"+t).eq(0).attr("checked",true);
		}else{
			$(".ceny"+t).eq(0).attr("checked",false);
		}
	}else{
		$("."+s).eq(0).attr("checked",true);
		$(".ceny"+t).eq(0).attr("checked",true);
	}
}
function admin_roleqx(u){
	if($(u).val()==1){
		$(".adminrole").show();
	}else{
		$(".adminrole").hide();
	}
}
function check_username(){
	var nm=$("#username").val();
	if(nm==''){
		$("#username").next("font").text('');
		return;
	}
	$.post("index.php?ac=ajax&ts=chkusername",
	{
		username:nm
	},
	function(msg){
		if(msg=='0'){
			$("#username").next("font").addClass("hred").removeClass("hblue").text("该用户名已存在！");
			$("#username").focus();
		}else{
			$("#username").next("font").addClass("hblue").removeClass("hred").text("用户名可以使用！");
		}
	});
}
function ckisqx(){
	var t=$("#isqx").val();
	if(t==2){
		$(".gymadmincell,.cenrole,.adminrole").hide();
		$("#centerset").show();
	}else if(t==0||t==999){
		$(".gymadmincell,.cenrole,.adminrole").hide();
	}else if(t==998){
		$(".gymadmincell").hide();
		$("#pareaset,#provset,.cenrole,.adminrole").show();
	}else if(t==3){
		$(".gymadmincell,.cenrole,.adminrole").hide();
		$("#centerrole,#pareaset,#provset").show();
//	}else if(t>10 && t<20){
//		$(".gymadmincell").hide();
//		$("#centerrole,#pareaset,#provset").show();
	}else{
		$(".gymadmincell,.cenrole,.adminrole").hide();
		$("#pareaset,#provset").show();
	}
}
function selfdcenter(obj){
	var t=$(obj).attr("vid");
	var nm=$(obj).attr("vname");
	if(t=='-1'){
		$("#cids").val(0);
		$("#carea").val(-1);
		$(".cdlist").html('<div class="flft mar hc" title="删除" onclick="delcenck(this,-1)">所有中心</div>');
	}else{
		var c=$("#cids").val();
		var a=$("#carea").val();
		var h=$(".cdlist").html();
		if(a=='-1'){
			return;
		}
		if(a!='-1'){
			$("#cids").val(t);
			$(".cdlist").html('<div class="flft mar hc" title="删除" onclick="delcenck(this,'+t+')">'+nm+'</div>');
		}else{
			$("#cids").val(c+','+t);
			$(".cdlist").html(h+'<div class="flft mar hc" title="删除" onclick="delcenck(this,'+t+')">'+nm+'</div>');
		}
	}
}
function delcenck(obj,t){
	if(t=='-1'){
		$("#cids").val('');
		$("#carea").val('');
	}else{
		var c=$("#cids").val();
		var b=c.split(',');
		for (var i=b.length-1;i>=0;i--){
			if(b[i]==t){
				b.splice(i,1);
			}
		}
		if(b.length==0){
			d='';
		}else{
			d=b.join(',');
		}
		$("#cids").val(d);
	}
	$(obj).remove();
}
//通用分页cookie设置
function ckpagesize(t){
	var w=$("#pagesize").val();
	var date=new Date();
	date.setTime(date.getTime()+365*24*3600*1000);
	document.cookie="mt_"+t+"_pnum="+w+";expires="+date.toGMTString();
	location.reload();
}
function gympage(){
	var t=parseInt($("#pageindex").val());
	var s=$("#pagenum").val();
	if(isNaN(t) || t==''){
		return;
	}
	if(t<1){
		t=1;
	}
	if(t>s){
		t=s;
	}
	var u=location.href;
	u=changeurlpar(u,'page',t);
	location.href=u;
}
function gymajaxpage(u,fun,para){
	var page=$(u).val();
	var pnum=$(u).next("input").val();
	var func;
	if(parseInt(page)<1){
		page=1;
	}
	if(parseInt(page)>parseInt(pnum)){
		page=pnum;
	}
	if(para==null){
		func=fun+'('+page+')';
	}else{
		func=fun+'('+para+','+page+')';
	}
	$(u).val(page);
	$(u).next().next("div").attr("onclick",func);
}
//通用选择框JS
function ckurlpara(w,s,t){
	var v=$("#"+w).val();
	var u=location.href;
	if(t!=''){
		var str=t.split(',');
		for(var i=0;i<str.length;i++){
			u=delurlpar(u,str[i]);
		}
	}
	location.href=changeurlpar(u,s,v);
}
function fdsearch(){
	var str=$("#fdsearch").val();
	var u=location.href;
	$.post("index.php?ac=ajax&ts=tounicode",
			{
				str:str
			},
			function(msg){
				location.href=changeurlpar(u,'keywords',msg);
			});
}
function gym_cktt(w,t){
	var s=$(w).attr("vid");
	var u=location.href;
	location.href=changeurlpar(u,t,s);
}
function gym_cktts(w,t){
	var s=$(w).val();
	var u=location.href;
	var a=changeurlpar(u,t,s);
	if(t=='isfr'){
		a=changeurlpar(a,"mcid",0);
		a=changeurlpar(a,"mid",0);
	}else if(t=='mcid'){
		a=changeurlpar(a,"mid",0);
	}
	location.href=a;
}
function gym_cktty(w,h,t){
	var s=$("#"+h).val();
	var u=location.href;
	location.href=changeurlpar(u,t,s);
}
function gym_cktp(){
	var s=$("#sdate").val();
	var w=$("#edate").val();
	var u=location.href;
	u=changeurlpar(u,'sd',s);
	location.href=changeurlpar(u,'ed',w);
}
function gym_cktpg(){
	var s=$("#gsdate").val();
	var w=$("#gedate").val();
	var u=location.href;
	u=changeurlpar(u,'gsd',s);
	location.href=changeurlpar(u,'ged',w);
}

function getttstr(obj,json,ck,mck){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=ajax&ts=getttstr",
			{
				ttlstr:json,
				ck:ck,
				mck:mck
			},
			function(msg){
				if(msg!=''){
					$(".mt_ad").show().html(msg);
					$(".mt_ad").css("left",x);
					$(".mt_ad").css("top",y+25);
					$(".mt_ad").css("width","150px")
				}
			});
}
function getfxstr(obj,keys,values,str,vs){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=ajax&ts=getfxstr",
			{
				keys:keys,
				values:values,
				str:str,
				vs:vs
			},
			function(msg){
				if(msg!=''){
					$(".mt_ad").show().html(msg);
					$(".mt_ad").css("left",x);
					$(".mt_ad").css("top",y+25);
					$(".mt_ad").css("width","150px");
					$(".mt_ad").css("max-height","500px");
					$(".mt_ad").css("overflow-y","auto");
				}
			});
}
function getdxstr(obj,keys,values,str,vs,ds){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=ajax&ts=getdxstr",
			{
				keys:keys,
				values:values,
				str:str,
				vs:vs,
				ds:ds
			},
			function(msg){
				if(msg!=''){
					$(".mt_ad").show().html(msg);
					$(".mt_ad").css("left",x);
					$(".mt_ad").css("top",y+25);
					$(".mt_ad").css("width","150px")
				}
			});
}
function chkdx(obj,str,ds){
	var hf=location.href;
	if(ds!=''){
		var h=ds.split('|');
		for(var i=0;i<h.length;i++){
			hf=delurlpar(hf,h[i]);
		}
	}
	location.href=changeurlpar(hf,trim(str),$(obj).val());
}
function chkfx(str){
	var ist=new Array();
	$("[name='gymfx[]']").each(function(){
		if($(this).is(":checked")==true){
			ist.push($(this).val());
		}
	})
	var hf=location.href;
	var w;
	if(ist.length>0){
		var tt=ist.join(',');
		w=changeurlpar(hf,trim(str),tt);
	}else{
		w=delurlpar(hf,trim(str));
	}
	if(trim(str)=='isfr'){
		var u=delurlpar(w,"ismc");
		w=delurlpar(u,"ism");
	}else if(trim(str)=='ismc'){
		w=delurlpar(w,"ism");
	}
	location.href=w;
}
function getdatestr(obj,sid,sstr,eid,estr,fun){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=ajax&ts=getdatestr",
			{
				sid:sid,
				sstr:sstr,
				eid:eid,
				estr:estr,
				fun:fun
			},
			function(msg){
				if(msg!=''){
					$(".mt_ad").show().html(msg);
					$(".mt_ad").css("left",x);
					$(".mt_ad").css("top",y+25);
					$(".mt_ad").css("width","150px")
				}
			});
}
function getddatestr(obj,dt,vdt,fun){
	var x=$(obj).offset().left;
	var y=$(obj).offset().top;
	$.post("index.php?ac=ajax&ts=getddatestr",
			{
				sid:dt,
				sstr:vdt,
				fun:fun
			},
			function(msg){
				if(msg!=''){
					$(".mt_ad").show().html(msg);
					$(".mt_ad").css("left",x);
					$(".mt_ad").css("top",y+25);
					$(".mt_ad").css("width","150px")
				}
			});
}
function fd_cktp(){
	var dt=$("#dt").val();
	var u=location.href;
	location.href=changeurlpar(u,'dt',dt);
}

